const superagent = require('superagent'); // superAgent 是以 utf8 去取数据
require('superagent-charset')(superagent); // 插件，可以指定获取数据格式
import { Injectable } from '@nestjs/common';
import { getHotNewsList } from '../util/common';
import { spider1 } from '../util/spider';
import { getStorage } from '../util/storage';

@Injectable()

export class InternetService {
    async getKr36() {
        const cach = getStorage('kr36');
        if (cach) {
            return cach;
        }
        const html = await spider1('http://36kr.com/', false);
        return getHotNewsList(html, 'kr36', '.kr-home-main .kr-home-flow .article-item-info .title-wrapper a', 'http://36kr.com');
    }

    async getAiri() {
        const cach = getStorage('airi');
        if (cach) {
            return cach;
        }
        const html = await spider1('https://www.iresearch.cn/', true);
        // @ts-ignore
        return getHotNewsList(html, 'airi', '.g-news .m-news #tab-list .m-item .txt a');
    }
}
